﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Cfg.MappingSchema;
using System.CodeDom;

namespace MVCGen.Generators.Entity {
	public class HbmListPropertyGenerator : ICodeTypeMemberGenerator {
		private HbmList list;
		private ICodeTypeMemberGenerator elementGenerator;

		public HbmListPropertyGenerator(HbmList list) {
			this.list = list;
			if (list.Item1 is HbmElement)
				this.elementGenerator = new HbmElementPropertyGenerator(list.name, list.Item1 as HbmElement);
			else if (list.Item1 is HbmManyToMany)
				this.elementGenerator = new HbmManyToManyPropertyGenerator(list.name, list.Item1 as HbmManyToMany);
			else if (list.Item1 is HbmCompositeElement)
				this.elementGenerator = new HbmCompositeElementPropertyGenerator(list.name, list.Item1 as HbmCompositeElement);
			else if (list.Item1 is HbmManyToAny)
				this.elementGenerator = new HbmManyToAnyPropertyGenerator(list.name, list.Item1 as HbmManyToAny);
			else if (list.Item1 is HbmOneToMany)
				this.elementGenerator = new HbmOneToManyPropertyGenerator(list.name, list.Item1 as HbmOneToMany);
			else
				throw new ArgumentException(String.Format("Unsupported bag item {0}", list.Item1.GetType().Name));
		}

		public CodeTypeMember Generate() {
			return elementGenerator.Generate();
		}
	}
}
